/////////////////////////////////////////////////////////////////////
//	$file: $
//	$revision: $
//	$author: $
//	$datetime: $
//	first author: buggy

#include	<QKeyEvent>
#include	<QDebug>

#include	"SourceNavigator.h"
#include	"StatusBar.h"

///////////////////////////////////////////////////////////
//	Source Navigator Status Bar
StatusBar::StatusBar(SourceNavigator* parentWidget)
	:	QLabel(parentWidget)
{
	_parentWidget	= parentWidget;
}

StatusBar::~StatusBar()
{
}

void StatusBar::Activate(const QString& str)
{
	setText(str);
	show();
}

void StatusBar::Deactivate()
{
	setText("");
	hide();
}

void StatusBar::focusInEvent(QFocusEvent* /*event*/)
{
	_parentWidget->setFocus();
	//(static_cast<QWidget*>(parent()))->focusInEvent(event);
}

void StatusBar::keyPressEvent(QKeyEvent* event)
{
	bool	update		= false;

	if (Qt::NoModifier == event->modifiers() && Qt::Key_Escape == event->key())
	{
		_parentWidget->CancelCommandInput();
	}
	else if ( Qt::NoModifier == event->modifiers() &&
			(Qt::Key_Return == event->key() || Qt::Key_Enter == event->key()) )
	{
		_parentWidget->BeginCommandInput( text() );
	}
	else if (Qt::NoModifier == event->modifiers() && Qt::Key_Backspace == event->key())
	{
		QString	str	= text();

		if (str.length() == 1)
		{
			_parentWidget->CancelCommandInput();
		}
		else if (str.length() > 1)
		{
			setText( str.remove( str.length() - 1, 1 ) );
			update	= true;
		}
	}
	else if (event->text().length() > 0)
	{
		QString	str	= text();

		setText( (str += event->text()) );
		update	= true;
	}

	if (update && text().at(0) == '/')
	{
		_parentWidget->UpdateSearch(text().remove(0, 1));
	}
}
